package pub.tbc.api.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Charsets;
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

/**
 * @author tbc on 2017/3/17 11:38:00.
 */
@Slf4j
public class FastJsonTest {

    public static void main(String[] args) throws IOException {
        assert args.length == 99;
        System.out.println("assert ");


    }

    private static void fastJson() throws IOException {
        String path = "D:\\Users\\tbc\\Desktop\\新建文本文档.txt";
        String json = getFileContent(path);
        log.debug("json=>\n {}", json);
        JSONObject jsonObject = JSON.parseObject(json);
        log.debug("jsonObject => \n{}", jsonObject);
        PromotionWareList ps = JSON.parseObject(json, PromotionWareList.class);
        System.out.println("\n\n\n");
        log.debug("PromotionWareList => \n {}", ps);

    }

    private static String getFileContent(String path) throws IOException {
        File file = new File(path);
        return Files.readAllLines(file.toPath(), Charsets.UTF_8)
                .stream()
                .reduce((pre, post) -> pre + post)
                .orElse("");
    }
}
